<template>
    <span>
        <Button type="primary" size="small" @click="handleLANIPAddShow">添加局域网地址</Button>
        <Modal v-model="lanip_add_modal" title="添加局域网地址" :mask-closable="false">
            <Form :model="lanip_current" :label-width="80">
                <FormItem label="名称">
                    <Input v-model="lanip_current.lanip_name" placeholder="请输入设备名称"></Input>
                </FormItem>
                <FormItem label="IP">
                    <Input v-model="lanip_current.lanip_ip" placeholder="请输入设备IP"></Input>
                </FormItem>
                <FormItem label="类型">
                    <Input v-model="lanip_current.lanip_type" placeholder="请输入设备类型"></Input>
                </FormItem>
            </Form>
            <template #footer>
                <Button type="primary" size="large" @click="handleLANIPAddOk">确定</Button>
                <Button type="text" size="large" @click="handleLANIPAddCancel">取消</Button>
            </template>
        </Modal>
    </span>
</template>

<script>
export default {
    name: 'LANIPAddButton',
    props: {
        client_id: String,
    },
    data () {
        return {
            lanip_add_modal: false,
            lanip_current: {
                lanip_id: 0,
                client_id: 0,
                lanip_name: '',
                lanip_type: '',
                lanip_ip: '',
                lanip_alive_time: '',
            }
        }
    },
    methods: {
        handleLANIPAddShow() {
            this.lanip_current.lanip_id = 0;
            this.lanip_current.lanip_name = '';
            this.lanip_current.lanip_type = '';
            this.lanip_current.lanip_ip = '';
            this.lanip_current.client_id = this.client_id;
            this.lanip_add_modal = true;
        },
        handleLANIPAddCancel() {
            this.lanip_add_modal = false;
        },
        handleLANIPAddOk() {
            this.$http.post('/add_lanip', this.lanip_current).then(res => {
                if (res.status == 'ok') {
                    this.$Message.success('添加成功');
                    this.lanip_add_modal = false;
                    this.$emit('success');
                } else {
                    this.errorMessage(res.data);
                }
            });
        }
    }
}
</script>